<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>应用日志</title>
    <link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
    <script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
    <script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
    <script type="text/javascript" src="D:\Project\FileTest\Download.log"></script>
    <a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout">

<div data-options="region:'west',split:false" style="width:20%;">
    <div style="height: 90%">
        <ul class="easyui-tree"  data-options="animate:true,lines:true" id="menu_app1" >
            <li><span>sss</span></li>
        </ul>
    </div>
</div>
<div data-options="region:'east',split:false" style="width:80%; overflow: hidden">
    <div data-options="region:'north',split:true" style="height:25px;width:100%;">
        <span >日志文件：</span>
        <span id="fileName"></span>
        <span>日志刷新间隔(秒)：</span>
        <span><input class="easyui-numberbox" value="5"  data-options="min:1,precision:0" id="refreshTime" style="width: 80px"></input></span>
    </div>
    <div data-options="region:'center',split:false" style="height: 96%">
        <tr>
            <td width="100%" aria-colspan="10"><input class="easyui-textbox" data-options="multiline:true" type="textarea"
                                                      id="logFile"
                                                      style="width: 100%;height: 100%"></input></td>
        </tr>
    </div>

</div>

</body>
<script>
    var head=0;
    var fileName;
    var appDeployId = $.getUrlParam("appDeployId");
    var isFirst = true;
    var fileNotCompleted = true;
    $(function (){
        $.restfulGet('../../api/sys/deploy/info/get/files/'+appDeployId,null,function (data){
            var treeData = "[";
            for (let i = 0; i <data.rows.files.length; i++) {
                if (i==0){
                    treeData+='{"id":"'+i+'","text":"'+data.rows.files[i]+'"}'
                } else {
                    treeData+=',{"id":"'+i+'","text":"'+data.rows.files[i]+'"}'
                }
            }
            treeData+="]"
            treeData =eval("(" + treeData + ")");
            $('#menu_app1').tree({
                data: [{
                    "text": "日志文件",
                    "state": "open",
                    "children": treeData
                }]
            });
        });
        $('#menu_app1').tree({
            onClick: function(node){
                fileNmae = node.text.replace(/\./g,"*");
                $('#fileName').html(node.text)
                //清空输出框
                $('#logFile').textbox("reset")
                //设置为第一次请求，请求最后1000行
                isFirst=true;
                file = "";
                //定时请求开启
                fileNotCompleted=true;
                getFile();
                timeRefresh(true);
            }
        });
    })
    var file="";
    function getFile(){
        $.restfulGet("../../api/sys/deploy/info/file/download/"+appDeployId+"/"+fileNmae+"/"+head+"/"+isFirst,null,function (data){
            isFirst =false;
            //请求内容为空时
            if ("" == data.rows.file){
                $('#logFile').textbox("setValue","此日志无内容")
            }else {
                file = data.rows.file+file;
                $('#logFile').textbox("setValue",file)
                head = data.rows.head;
                //日志文件全部加载完成
                if (head==1){
                    file = "日志内容全部加载完成，停止刷新！\n"+file;
                    $('#logFile').textbox("setValue",file)
                    fileNotCompleted = false;
                }
            }
        })
    }

    function timeRefresh(first) {
        if (!first) {
            getFile();
        }
        if (fileNotCompleted){
            var refreshTime = $('#refreshTime').textbox("getValue") ;
            window.setTimeout("timeRefresh()", refreshTime * 1000);
        }
    }
</script>
</html>